import { RandUtil } from "../../util/RandUtil";
import BaseAI, { IBaseAI } from "./BaseAI";

const ru = RandUtil

export interface IAITurn extends IBaseAI {
    turnSpd: number | [number, number]
}

export default class AITurn extends BaseAI {

    private _turnSpdArr: number[]
    private _turnSpd: number

    constructor(obj: IAITurn) {
        super(obj)
        this._turnSpdArr = this.toMinMax(obj.turnSpd)
    }

    getKey(): string { return "ai_turn" }

    aiStart() {
        let turn = ru.chance(0.5) ? -1 : 1
        this._turnSpd = turn * ru.rand2(this._turnSpdArr)
    }

    ai(dt: number): void {
        let head = this.head
        let turnAng = head.getTurnSpd() * this._turnSpd * dt
        head.toAng = head.ang + turnAng;
    }

    aiStop() {

    }

}